package somepackage;

import org.fest.assertions.Assertions;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.LoadableComponent;

public class IndexPage extends LoadableComponent<IndexPage> {
	private final WebDriver driver;

	@FindBy(name = "j_idt7:j_idt9")
	private WebElement blah;

	@FindBy(name = "j_idt7:j_idt11")
	private WebElement submit;

	public IndexPage(WebDriver driver) {
		super();
		this.driver = driver;
		PageFactory.initElements(driver, this);
	}

	@Override
	protected void isLoaded() throws Error {
		Assertions.assertThat(driver.getTitle()).isEqualTo(
				"JSF 2.2: Blank Starting-Point Project");

	}

	@Override
	protected void load() {
		driver.get("http://localhost:8080/foo/");
	}

	public void setBlah(String string) {
		blah.sendKeys(string);
	}

	public PageBPage submitToPageB() {
		submit.click();
		return new PageBPage(driver);
	}

}
